package com.cntv.viewmodeldemo.databinding;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;

import com.cntv.viewmodeldemo.R;
import com.cntv.viewmodeldemo.databinding.ActivityMainBinding;
import com.cntv.viewmodeldemo.livedata.MyLiveDataViewModel;

/**
 * Created By Mahongyin
 * Date    2020/9/17 14:24
 * ViewModel  LiveData  DataBinding 使用
 */
public class MainActivity extends AppCompatActivity {
    ActivityMainBinding binding;
    MyLiveDataViewModel viewModel;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_main);

        viewModel = new ViewModelProvider(this).get(MyLiveDataViewModel.class);

        binding.setData(viewModel);
        binding.setLifecycleOwner(this);

    }
}
